#include <ne.h>
#include <QtOpenGL>
#include "EditorRender.h"

class GLWidget : public QGLWidget
{
    Q_OBJECT

    public:
        GLWidget(QWidget *parent=0);

        virtual ~GLWidget();

        void formatCamera();

        void createQuad();

        void deleteQuad();

    protected:
        virtual void initializeGL();
        virtual void paintGL();
        virtual void resizeGL(int width, int height);

        virtual void mouseMoveEvent(QMouseEvent *event);
        virtual void mousePressEvent(QMouseEvent *event);
        virtual void mouseReleaseEvent(QMouseEvent *event);
        virtual void mouseDoubleClickEvent(QMouseEvent *event);
        virtual void wheelEvent(QWheelEvent *event);

        virtual void keyPressEvent(QKeyEvent *event);
        virtual void keyReleaseEvent(QKeyEvent *event);

        virtual void timerEvent(QTimerEvent *) { update(); }

    public:
        static ne::MouseButton ConvertQTMouseButton(const Qt::MouseButton button);
        static ne::KeyboardModifier ConvertQTKeyboardModifier(const Qt::KeyboardModifier modifier);

    private:
        ne::Engine *mpEngine;
        ne::Viewport *mpViewport;
        ne::Camera *mpCamera;
        ne::Vector3 mCameraLookAt;
        ne::real mCameraDistance;
        ne::real mCameraYaw;
        ne::real mCameraPitch;
        ne::Light *mpLight;

        EditorRender *mpRender;

        int mNumQuad;
        ne::Vector3 mQuadPos;
};
